package com.lizk.study.netty.day009;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 随机读写文件、内存映射的buffer的使用
 * @author lizhikui
 * @date 2019/6/25 23:54
 */
public class NioTest9 {
    public static void main(String[] args) throws IOException {


        File file = FileUtil.createFile("NioTest9.properties");

        System.out.println(NioTest9.class.getResource("NioTest9.properties").getFile());

        RandomAccessFile randomAccessFile = new RandomAccessFile(NioTest9.class.getResource("NioTest9.properties").getFile(), "rw");
        FileChannel fileChannel = randomAccessFile.getChannel();
        byte[] bytes = "ssssss".getBytes();
        MappedByteBuffer map = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, bytes.length);
        map.put(bytes);
        map.clear();

        randomAccessFile.close();
    }
}
